/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import model.estrutura.MalhaIrregular;

/**
 *
 * @author Thiago
 */
public class ManipuladorArquivo {

    private MalhaIrregular malhaIrregular;
    private Camera camera;
    private Heightmap heig;

    public ManipuladorArquivo(MalhaIrregular malhaIrregular, Camera cam) {
        this.malhaIrregular = malhaIrregular;
        this.camera = cam;
    }
    
    public ManipuladorArquivo(Heightmap heig){
        this.heig = heig;
    }

    public void saveFile(String arq) {
        try {
            ObjectOutputStream objectOut = new ObjectOutputStream(new FileOutputStream(arq));
            objectOut.writeObject(this.camera);
            objectOut.writeObject(this.malhaIrregular);
            objectOut.flush();
            objectOut.close();
        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }

    public void openFile(String arq) throws ClassNotFoundException {
        try {
            ObjectInputStream objectIn = new ObjectInputStream(new FileInputStream(arq));
            this.camera = (Camera) objectIn.readObject();
            this.malhaIrregular = (MalhaIrregular) objectIn.readObject();
            objectIn.close();
        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }
    
    public void saveHeightMap(String arq) {
        try {
            ObjectOutputStream objectOut = new ObjectOutputStream(new FileOutputStream(arq));
            objectOut.writeObject(this.heig);
            objectOut.flush();
            objectOut.close();
        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }

    public void openHeightMap(String arq) throws ClassNotFoundException {
        try {
            ObjectInputStream objectIn = new ObjectInputStream(new FileInputStream(arq));
            this.heig = (Heightmap) objectIn.readObject();
            objectIn.close();
        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }

    public MalhaIrregular getMalhaIrregular() {
        return malhaIrregular;
    }

    public Camera getCamera() {
        return camera;
    }

    public Heightmap getHeig() {
        return heig;
    }
    
    
    
}
